from flask import Blueprint, request, jsonify
from utils.deepseek import DeepSeekAPI
import traceback

ppt_bp = Blueprint('ppt', __name__)

deepseek = DeepSeekAPI()

@ppt_bp.route('/')
def index():
    return 'Hello, AI PPT Generator!'

@ppt_bp.route('/genppt', methods=['POST'])
def generate_ppt():
    try:
        data = request.get_json()
        if not data or 'prompt' not in data:
            return jsonify({
                'success': False,
                'error': 'Prompt is required'
            }), 400
            
        prompt = data.get('prompt', '').strip()  # 去除空白字符
        if not prompt:  # 检查空字符串
            return jsonify({
                'success': False,
                'error': 'Prompt is required'
            }), 400
            
        # 调用 DeepSeek API
        response = deepseek.chat_completion(prompt)
        
        return jsonify({
            'success': True,
            'data': response
        })
        
    except Exception as e:
        print(f"Error in /genppt: {str(e)}")
        print(traceback.format_exc())
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500 